package com.honey.mybatis.generator.mappper;

import com.honey.compilation.xml.XmlElement;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.dbmapping.structure.Schema;
import com.honey.mybatis.generator.MybatisPlugin;

public class SelectCount extends AbstractMybatisMapper{

	public SelectCount(MybatisPlugin belongPlugin) {
		super(belongPlugin);
	}

	public void appendElement(XmlElement parent, Schema schema, IntrospectSchemaColumn introspectSchemaColumn ){
		parent.addNewLine();
		parent.addComments(
				"按照条件查询记录集总数量"
		);
//		new XmlElement(
//					new XmlElement(
//					,"if")
//						.addAttribute("test","_parameter != null")
//					,
//			"include")
//			.addAttribute("refid", "dynamic.condition.defaultDynamic")
//		;
		
		XmlElement select = new XmlElement(parent,"select")
		.addAttribute("id",MapperConstant.SELECT_COUNT_MAPPER_ID)
		.addAttribute("parameterType",super.getModelPrimitiveClassType(schema).getLongName())
		.addAttribute("resultType", "java.lang.Integer")
		.addAttribute("timeout", mybatisPlugin.getConnectionTimeOut());

		select.addTextElement("SELECT COUNT(*) FROM "+ schema.getName()) ;
		addDefaultDynamicCondition(select,introspectSchemaColumn.allColumns());
	}
}
